import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:extended_text_field/extended_text_field.dart';

void main() {
  testWidgets('ExtendedTextField should be created successfully', (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          body: ExtendedTextField(
            controller: TextEditingController(),
            focusNode: FocusNode(),
          ),
        ),
      ),
    );

    // Verify that the ExtendedTextField is rendered
    expect(find.byType(ExtendedTextField), findsOneWidget);
  });

  testWidgets('ExtendedTextField should accept text input', (WidgetTester tester) async {
    final TextEditingController controller = TextEditingController();
    final FocusNode focusNode = FocusNode();
    
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          body: ExtendedTextField(
            controller: controller,
            focusNode: focusNode,
          ),
        ),
      ),
    );

    // Tap on the ExtendedTextField to focus it
    await tester.tap(find.byType(ExtendedTextField));
    await tester.pump();
    
    // Manually set text since enterText might not work with ExtendedTextField
    controller.text = 'Hello World';
    
    // Verify the text was entered
    expect(controller.text, 'Hello World');
  });

  testWidgets('ExtendedTextField should support special text span builder parameter', (WidgetTester tester) async {
    final TextEditingController controller = TextEditingController();
    final FocusNode focusNode = FocusNode();
    
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          body: ExtendedTextField(
            controller: controller,
            focusNode: focusNode,
            // Test that the specialTextSpanBuilder parameter is accepted
            specialTextSpanBuilder: null,
          ),
        ),
      ),
    );

    // Verify that the ExtendedTextField is rendered with specialTextSpanBuilder parameter
    expect(find.byType(ExtendedTextField), findsOneWidget);
  });

  testWidgets('ExtendedTextField should support extended context menu builder', (WidgetTester tester) async {
    final TextEditingController controller = TextEditingController();
    final FocusNode focusNode = FocusNode();
    
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          body: ExtendedTextField(
            controller: controller,
            focusNode: focusNode,
            // Test that the extendedContextMenuBuilder parameter is accepted
            extendedContextMenuBuilder: (BuildContext context, ExtendedEditableTextState state) {
              return Container();
            },
          ),
        ),
      ),
    );

    // Verify that the ExtendedTextField is rendered with extendedContextMenuBuilder parameter
    expect(find.byType(ExtendedTextField), findsOneWidget);
  });

  testWidgets('ExtendedTextField should support maxLines parameter', (WidgetTester tester) async {
    final TextEditingController controller = TextEditingController();
    final FocusNode focusNode = FocusNode();
    
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          body: ExtendedTextField(
            controller: controller,
            focusNode: focusNode,
            maxLines: 5,
          ),
        ),
      ),
    );

    // Verify that the ExtendedTextField is rendered with maxLines parameter
    expect(find.byType(ExtendedTextField), findsOneWidget);
  });
}